﻿/**
 * ...
 * @author Sergey Mamyan
 */
package tx.squirrel.neko.admin.handler;
 
import mtwin.web.Request;
import neko.Web;

import tx.squirrel.neko.core.handler.BaseHandler;
import tx.squirrel.neko.core.model.Config;
import tx.squirrel.neko.core.model.Session;
import tx.squirrel.neko.core.model.User;

class UserHandler extends BaseHandler {

	public function new() {
		super();
		//logged("default", 	"admin_user.mtt", 			doDefault	);
		//logged("edit", 		"admin_user_modify.mtt", 	doEdit		);
		//logged("show", 		"admin_user_modify.mtt", 	doShow		);
		//logged("add", 		"admin_user_modify.mtt", 	doAdd		);
	}
	/*
	public function doDefault():Void {
		display(User.manager.all());
	}
	
	public function doShow():Void {
		var userId:Int = Std.parseInt(argument(1));
		var user:User = User.manager.get(userId);
		if (user != null) {
			display({
			user:user,
			action:"show"
			});
		}else {
			Session.writeLog("error","User with id <"+argument(1)+"> unavailable.");
			redirect("/admin/user");
		}
	}
	
	public function doAdd():Void {
		var userId:Int = Std.parseInt(argument(1));
		var user:User = new User();
		
		if (Web.getMethod() == "POST") {
			var postUser:Hash<String> = Web.getParams();
			user.fullName 	= postUser.get("fullName");
			user.email 		= postUser.get("email");
			user.password 	= postUser.get("password");
			user.insert();
			user.sync();
			Session.writeLog("info","User <"+user.id+","+user.name+"> successfuly added");
			redirect("/admin/user");
		}else{
			display({
				user:user,
				action:"add"
			});
		}
	}
	
	public function doEdit():Void {
		var userId:Int = Std.parseInt(argument(1));
		var user:User = User.manager.get(userId);
		if (user != null) {
			if (Web.getMethod() == "POST") {
				var postUser:Hash<String> = Web.getParams();
				user.name	 	= postUser.get("name");
				user.update();
				Session.writeLog("info","User <"+user.id+","+user.name+"> successfuly updated");
				redirect("/admin/user");
			}else{
				display({
					user:user,
					action:"edit"
				});
			}
		}else{
			Session.writeLog("error","User with id <"+argument(1)+"> unavailable.");
			redirect("/admin/user");
		}
	}
	*/
}